//
//  ClickImageViewer.m
//  ChimooTimer
//
//  Created by Ryan on Thu Oct 09 2003.
//  Copyright (c) 2003 __MyCompanyName__. All rights reserved.
//

#import "ClickImageViewer.h"


@implementation ClickImageViewer

- (id)initWithFrame:(NSRect)frameRect
{
	[super initWithFrame: frameRect];

	showURL = NO;

	if ([self window] != nil) {
		[[self window] makeFirstResponder:self];
		[[self window] setAcceptsMouseMovedEvents: YES];
		[[self window] addTrackingRect:[self frame]
						owner:self
						userData:nil
						assumeInside:NO];
	}

	return self;
}


- (void)setShowURL:(BOOL)b {
	showURL = b;
}


- (void)setURLToShow:(NSURL *)url {
	if (urlToShow != url) {
		[urlToShow release];
		urlToShow = [url retain];
	}
	[self setShowURL: YES]; //set it to show by default.
}


- (void)mouseDown:(NSEvent *)event
{
	//NSLog(@"mousedown: %d", [event clickCount]);
	if (showURL) {
		[[NSWorkspace sharedWorkspace] openURL:urlToShow];
	}
}


- (void)mouseEntered:(NSEvent *)event
{
	//NSLog(@"mouseEntered");
	if (showURL) {
		//underline the text
  //		[self underline];
		//[[self textStorage] addAttributes: NSUnderlineStyleAttributeName range: all];
	}
}

- (void)mouseExited:(NSEvent *)event
{
	//NSLog(@"mouseExited");
	if (showURL) {
		//remove underlining.
		//[[self textStorage] removeAttributes: NSUnderlineStyleAttributeName range: all];
	}
}

@end

